#!/usr/bin/env python
# encoding: utf-8
# @author: Lin Han
# @contact: voldemort22@126.com
# @file: transfer_original_data.py
# @time: 2021/3/19 9:44
# @desc:

import pymongo

from .utils.utils import *

myclient = pymongo.MongoClient("mongodb://10.8.1.11:27017")
mydb = myclient["DoDesignData"]


# 夹具列表
mycol = mydb["clamp_t"]
cursor = mycol.find({})

clamp_t = []
for i in cursor:
    clamp_t.append(i)

mapping_list = [{i["CGuid"]:i["number"]} for i in clamp_t if "number" in i.keys()]

# Index列表
index = mydb["Index"]
cursor = index.find({})

index_list = []
for i in cursor:
    index_list.append(i)

training = [i for i in index_list if i["Relation"] == "training"][0]

# 现在training是一个字典，一个字段Relation是"training"，另一个Index是要换的对象。
for i in training["Indexes"].keys():
    training["Indexes"][i]


print(clamp_t[0])

new_clamp_t_0 = transfer_clamp_t(clamp_t[0])

# 将clamp_t集合中的所有数据，转化成新格式后存入新的集合new_clamp里
new_clamp = []
for i in clamp_t:
    print(i)
    new_clamp.append(transfer_clamp_t(i))

new_clamp_collection = mydb["new_clamp"]
new_clamp_collection.insert_many(new_clamp)

# 下面是夹具的零件
my_part_collection = mydb["standard_part"]
cursor = my_part_collection.find({})

part = []
for i in cursor:
    part.append(i)

part_0 = transfer_part(part[0])















